package com.e.ticket;

import androidx.annotation.Nullable;
import androidx.appcompat.app.AppCompatActivity;
import androidx.fragment.app.Fragment;

import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.content.SharedPreferences.Editor;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;

import com.e.Dao.UserDao;
import com.e.Pojo.User;
import com.e.SQL.UserDBHepler;

public class Own extends Fragment {
    Button bt_password,bt_logout;
    TextView tv_name,tv_ssex,tv_phone,tv_college,tv_sdept,tv_sno;
    final String FILE_NAME="user";
    private UserDao userDao;



    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View v = LayoutInflater.from(this.getActivity()).inflate(R.layout.activity_own, null);
        return v;
    }

    @Override
    public void onActivityCreated(@Nullable Bundle savedInstanceState){
        super.onActivityCreated(savedInstanceState);
        userDao = new UserDao(new UserDBHepler(getActivity()));
        SharedPreferences sp = getActivity().getSharedPreferences(FILE_NAME, Context.MODE_PRIVATE);
        String sno = sp.getString("sno","");
        bt_logout = (Button)getActivity().findViewById(R.id.bt_logout);
        bt_password = (Button)getActivity().findViewById(R.id.up_password);
        tv_name = (TextView)getActivity().findViewById(R.id.tv_sname);
        tv_sno = (TextView)getActivity().findViewById(R.id.tv_sno);
        tv_ssex = (TextView)getActivity().findViewById(R.id.tv_ssex);
        tv_college = (TextView)getActivity().findViewById(R.id.tv_college);
        tv_sdept = (TextView)getActivity() .findViewById(R.id.tv_sdept);
        tv_phone = (TextView)getActivity().findViewById(R.id.tv_phone);

        User u = userDao.findUserBySno(sno);
        tv_name.setText(u.getSname());
        tv_sno.setText(u.getSno());
        tv_ssex.setText(u.getSsex());
        tv_college.setText(u.getCollege());
        tv_sdept.setText(u.getSdept());
        tv_phone.setText(u.getPhone());

    bt_logout.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            startActivity(new Intent(getActivity(),Login.class));
            getActivity().finish();
        }
    });

    bt_password.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View view) {
            Intent intent = new Intent(getActivity(),Update_password.class);
            Bundle bundle = new Bundle();
            bundle.putString("sno",u.getSno());
            bundle.putString("password",u.getPassword());
            intent.putExtras(bundle);
            startActivity(intent);
        }
    });

    }






}